package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.c5.C5Account;
import com.ruoyi.system.service.IC5AccountService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * C5Game账户Controller
 *
 * @author ruoyi
 * @date 2025-10-15
 */
@Controller
@RequestMapping("/system/account")
public class C5AccountController extends BaseController {
    private String prefix = "system/account";

    @Autowired
    private IC5AccountService c5AccountService;

    @RequiresPermissions("system:account:view")
    @GetMapping()
    public String account() {
        return prefix + "/account";
    }

    /**
     * 查询C5Game账户列表
     */
    @RequiresPermissions("system:account:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(C5Account c5Account) {
        startPage();
        List<C5Account> list = c5AccountService.selectC5AccountList(c5Account);
        return getDataTable(list);
    }

    /**
     * 导出C5Game账户列表
     */
    @RequiresPermissions("system:account:export")
    @Log(title = "C5Game账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(C5Account c5Account) {
        List<C5Account> list = c5AccountService.selectC5AccountList(c5Account);
        ExcelUtil<C5Account> util = new ExcelUtil<C5Account>(C5Account.class);
        return util.exportExcel(list, "C5Game账户数据");
    }

    /**
     * 新增C5Game账户
     */
    @RequiresPermissions("system:account:add")
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存C5Game账户
     */
    @RequiresPermissions("system:account:add")
    @Log(title = "C5Game账户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(C5Account c5Account) {
        return toAjax(c5AccountService.insertC5Account(c5Account));
    }

    /**
     * 修改C5Game账户
     */
    @RequiresPermissions("system:account:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        C5Account c5Account = c5AccountService.selectC5AccountById(id);
        mmap.put("c5Account", c5Account);
        return prefix + "/edit";
    }

    /**
     * 修改保存C5Game账户
     */
    @RequiresPermissions("system:account:edit")
    @Log(title = "C5Game账户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(C5Account c5Account) {
        return toAjax(c5AccountService.updateC5Account(c5Account));
    }

    /**
     * 删除C5Game账户
     */
    @RequiresPermissions("system:account:remove")
    @Log(title = "C5Game账户", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(c5AccountService.deleteC5AccountByIds(ids));
    }

    /**
     * 删除C5Game账户
     */
    @PostMapping("/refreshAccountInfo")
    @ResponseBody
    @DataSource(value = DataSourceType.CS)
    public AjaxResult refreshAccountInfo(String appKey) {
        return toAjax(c5AccountService.refreshAccountInfo(appKey));
    }
}
